<?php
/**
 * 后台站点操作模型
 *
 * created by.
 * User: EDZ
 * Date: 2020/9/12
 * TIME: 14:40
 */

namespace app\admin_libaray\model;
use think\Model;


class SiteModel extends Model{

    public $name = 'site';

    /**
     * 站点默认数据
     *
     * @var array
     */
    private $data = [
        'id'        =>  1,
        'name'      =>  'personalSite',
        'status'    =>  'yes',
        'create_date'   =>  0,
        'update_date'   =>  0,
        'last_time_date'    =>  0
    ];

    /**
     * 站点开始前的系统操作
     *
     * SiteModel constructor.
     * @param array $data
     */
    public function __construct($data = []) {
        parent::__construct($data);
    }

    /**
     * 增加默认站点状态
     *
     * @author qf
     * @date 2020/9/26 14:57
     */
    private function insertSite(){
       return self::strict(false)->insert($this->data);
    }

    /**
     * 获取当前站点状态
     *
     * @param bool $newGet 避免死循环
     * @author qf
     * @date 2020/9/26 14:21
     */
    public static function getSiteStatus($newGet = false){
        if ($newGet == true) return 'no';   //脱离死循环
        $siteInfo = self::where(['id' => 1])->value('status');
        if (empty($siteInfo)){
            self::insertSite();
            self::getSiteStatus(true);
        }
        return $siteInfo;
    }

}